
/**
 * 数据精度
 * 123.45：precision = 5 ，scale = 2
 */
class PrecisionScale {
    /**
     * 数据长度 
     */ 
    precision?: number;
    /**
     * 小数长度
     */
    scale?: number;
    constructor(precision: number, scale){
        this.precision = precision;
        this.scale = scale;
    }
}

class JavaTypeConvertor {
    dbType: string;
    javaType: string;
    renderFun?: Function;
    constructor(dbType: string, javaType: string, renderFun?: Function){
        this.dbType = dbType;
        this.javaType = javaType;
        this.renderFun = renderFun;
    }
    convert(precisionScale? : PrecisionScale){
        if(!!this.renderFun){
            return this.renderFun(this.dbType, this.javaType, precisionScale);
        }
        return this.javaType
    }
}

const convertor = (dbType: string, javaType: string, renderFun?: Function) : JavaTypeConvertor =>{
    return new JavaTypeConvertor(dbType, javaType, renderFun);
}

const JavaType = {
    Character : 'Character',
    String : 'String',
    Integer : 'Integer',
    Long : 'Long',
    Float : 'Float',
    Double : 'Double',
    BigDecimal : 'BigDecimal',
    Date : 'Date',
    Byte : 'Byte',
    Blob : 'Blob',
    Boolean : 'Boolean'
}

export {PrecisionScale, JavaType, JavaTypeConvertor, convertor}